package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.CleaningDao;
import cn.topevery.garden.entity.po.Cleaning;
import cn.topevery.garden.entity.query.CleaningQuery;
import cn.topevery.garden.entity.vo.CleaningVO;

import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.DataFillHelper;
import hw.topevery.framework.db.CommandType;
import hw.topevery.framework.db.DataReader;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.Value;
import hw.topevery.framework.entity.KeyValue;
import hw.topevery.framework.enums.DbTypeEnum;
import hw.topevery.framework.util.LogUtil;
import hw.topevery.framework.db.DbScriptHelper;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

/**
 * 清扫保洁管理
 *
 * @author code-generate
 * @date 2022-11-25
 */
@Repository
public class CleaningDaoImpl extends BaseDaoImpl<Cleaning> implements CleaningDao {
    @Override
    public <P extends DbCsp> List<Cleaning> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<CleaningVO> listPage(CleaningQuery query) {
        String table = "t_cleaning t\n" +
                "LEFT JOIN t_company tc ON tc.c_company_id = t.c_company_id\n" +
                "LEFT JOIN t_person tp ON tp.c_user_id = t.c_cleaner_id\n" +
                "LEFT JOIN t_car tc2 ON tc2.c_car_id = t.c_car_id";

        String columns = "t.*,tc.c_name companyName,tp.c_name cleaner,tc2.c_car_num carNum";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tc.c_id desc");
        sqlQueryMate
                .where(true, "t.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotBlank(query.getCompanyId()), "t.c_company_id", ScriptConditionEnum.Eq, query.getCompanyId())
                .where(StringUtils.isNotBlank(query.getCleanerId()), "t.c_cleaner_id", ScriptConditionEnum.Eq, query.getCleanerId())
                .where(StringUtils.isNotBlank(query.getCarId()), "t.c_car_id", ScriptConditionEnum.Eq, query.getCarId())
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, CleaningVO.class);
    }

    @Override
    public Cleaning getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }
}
